/*
 * Copyright 2012-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.web.context;

import org.springframework.boot.web.server.WebServer;
import org.springframework.context.ApplicationEvent;

/**
 * 当{@link WebServer}准备就绪时要发布的事件。用于获取运行中服务器的本地端口。
 * @author Brian Clozel
 * @author Stephane Nicoll
 * @since 2.0.0
 */
@SuppressWarnings("serial")
public abstract class WebServerInitializedEvent extends ApplicationEvent {

	protected WebServerInitializedEvent(WebServer webServer) {
		super(webServer);
	}

	/**
	 * 访问{@link WebServer}。
	 * @return 嵌入式Web服务器
	 */
	public WebServer getWebServer() {
		return getSource();
	}

	/**
	 * 访问创建服务器的应用程序上下文。有时在对服务器本身进行操作之前，
	 * 检查这是否符合期望（如等于当前上下文）是明智的。
	 * @return 创建服务器的应用程序上下文
	 */
	public abstract WebServerApplicationContext getApplicationContext();

	/**
	 * 访问事件源（一个{@link WebServer}）。
	 * @return 嵌入式Web服务器
	 */
	@Override
	public WebServer getSource() {
		return (WebServer) super.getSource();
	}

}
